﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace SAHCPIMS_final
{
    public partial class ADDPRENATAL : Form
    {
        public string homeEmpName;
        public int homeEmpNum;

        public int famNum;
        public string fname;
        public string mname;
        public string lname;
        public string bdate;
        
        public ADDPRENATAL()
        {
            InitializeComponent();
        }

        private void logOutButton_Click(object sender, EventArgs e)
        {
            LOGIN logout = new LOGIN();
            logout.Visible = true;
            this.Visible = false;
        }

        private void ADDPRENATAL_Load(object sender, EventArgs e)
        {
            this.familyNumberMismo.Text = famNum.ToString();
            this.familyInformationLabel.Text = fname + " " + mname + " " + lname;
            this.bDateInfo.Text = bdate;
            this.checkupTypeInfo.Text = "Prenatal";
            this.checkupDate.Text = DateTime.Now.ToShortDateString();

            this.employeeLabel.Text = homeEmpName;
            this.empNumLabel.Text = homeEmpNum.ToString();
        }

        private void homebutton_Click(object sender, EventArgs e)
        {
            HOME home = new HOME();
            home.homeEmpName = homeEmpName;
            home.homeEmpNum = homeEmpNum;
            home.Visible = true;
            this.Visible = false;
        }

        private void cancel_Click(object sender, EventArgs e)
        {
            HOME home = new HOME();
            home.homeEmpName = homeEmpName;
            home.homeEmpNum = homeEmpNum;
            home.Visible = true;
            this.Visible = false;
        }

        private void acceptbutton_Click(object sender, EventArgs e)
        {
            //Connection String
            string conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\SAHCPIMS_database.mdb";
            OleDbConnection conn = new OleDbConnection(conString);
            DataSet ds = new DataSet();
            //opens the connection to the database
            conn.Open();
            //try to add entry in the Vaccine table
            try
            {
                OleDbDataAdapter tagalagay = new OleDbDataAdapter("Insert into Prenatal values ('"
                    + famNum + "','" + fname + "','" + mname + "','" + lname + "','" + DateTime.Now.ToShortDateString() + "','"
                    + this.xpcted.Text + "','" + this.aog.Text + "','" + this.lmp.Text + "','" + this.gravida.Text
                    + "','" + this.para.Text + "')", conn);
                tagalagay.Fill(ds);
            }
            catch (OleDbException)
            {
                MessageBox.Show("Data Already Exist");
            }
            try
            {
                OleDbDataAdapter tagalagay = new OleDbDataAdapter("Insert into ToxoidPrenatal values ('"
                    + famNum + "','" + fname + "','" + mname + "','" + lname + "','" + this.gravida.Text+"','" 
                    + DateTime.Now.ToShortDateString() + "')", conn);
                tagalagay.Fill(ds);
            }
            catch (OleDbException)
            {
                this.prompt.Text = "Data Already Exist";
            }
            conn.Close();

            this.weightLabel.Text = this.weight.Text;
            this.GravLabel.Text = this.gravida.Text;
            this.EDDlabel.Text = this.xpcted.Text;
            this.LMPlabel.Text = this.lmp.Text;
            this.AOGlabel.Text = this.aog.Text;
            this.parLabel.Text = this.para.Text;
            if (this.toxcheckBox.Checked) this.ToxoidLabel.Text = DateTime.Now.ToShortDateString();

            this.panel2.Visible = false;
            this.success.Visible = true;

        }


    }
}
